package com.mysqldemo.service.serviceImpl;
import javax.annotation.Resource;
import com.mysqldemo.mappers.TestMapper;

import com.mysqldemo.service.TestService;

import com.mysqldemo.entity.po.Test;

import com.mysqldemo.entity.query.TestQuery;

import com.mysqldemo.entity.vo.PaginationResultVO;

import org.springframework.stereotype.Service;

import java.util.List;

import com.mysqldemo.enums.PageSize;

import com.mysqldemo.entity.query.SimplePage;

/**
 * @Description Mapper
 * @Author 徐大勇
 * @Version 1.8.0_131
 * @date 2023/07/06
 */
@Service("TestService")
public class TestServiceImpl implements TestService {

	@Resource
	private TestMapper<Test,TestQuery> TestMapper;

	@Override
//通过TestQuery查询
	public List<Test> selectByParam(TestQuery query){
		return this.TestMapper.selectList(query);
	}

	@Override
//通过条件查询数量
	public Integer selectCountByParam(TestQuery query){
		return this.TestMapper.selectCount(query);
	}

	@Override
//分页查询
	public PaginationResultVO<Test> findListByPage(TestQuery query){
		Integer count = this.selectCountByParam(query);
		int pageSzie = query.getPageSize() == null? PageSize.SIZE15.getSize():query.getPageSize();
		SimplePage page = new SimplePage(query.getPageNo(),count,pageSzie);
		List<Test> list = this.selectByParam(query);
		PaginationResultVO<Test> resultVO = new PaginationResultVO<>(count,page.getPageSize(),page.getPageNo(),list);
		return  resultVO;

	}

	@Override
//插入
	public Integer add(Test bean){
		return this.TestMapper.insert(bean);
	}

	@Override
//批量插入
	public Integer addBatch(List<Test> list){
		if(list == null || list.size() == 0){
			return 0;
		}
		return this.TestMapper.insertBatch(list);
	}
	@Override
//批量插入或更新
	public Integer addOrUpdateBatch(List<Test> list){
		if(list == null || list.size() == 0){
			return 0;
		}
		return this.TestMapper.updateOrInsert(list);
	}


	@Override
//通过Id查询
	public Test getById(Integer id) {
		return this.TestMapper.selectById(id);
	}

	@Override
//通过Id更新
	public Integer updateById(Test bean , Integer id) {
		return this.TestMapper.updateById(bean,id);
	}

	@Override
//通过Id删除
	public Integer deleteById(Integer id) {
		return this.TestMapper.deleteById(id);
	}

}
